/*
 * CommandHandler.h
 *
 *  Created on: 13.12.2012
 *      Author: Lapchinskiy
 */

#ifndef COMMANDHANDLER_H_
#define COMMANDHANDLER_H_
#include "Task.h"
#define MAX_CMD_STRING_LENTH 50
#define  MAX_COMMAND_NUMBER 10
typedef enum {
	TASK_LIST,
	TOP,
	READ_BY_ADDR,
	WRITE_TO_ADDR,
	TASK_FUNC_EXECUTE,
	TASK_ENABLE,
	TASK_DISABLE,
	LOGGING_ENABLE,
	LOGGING_DISABLE,
	CLEAR_SCREEN,
    FALSE_CMD,
} CommandType;
class CommandHandler {

private:
       static const char* commandNotFoundResponse;
       static const char *CommandHandler::permissionDeniedResponse;
       static const char *CommandHandler::okResponse;
       static const char  commandsTable[MAX_COMMAND_NUMBER][MAX_CMD_STRING_LENTH];
       static uint8_t* messageBuf;
       static ArrayList*globalTaskList;

public:
	CommandHandler();
        static const uint8_t messageEndChar;

	static ErrorCode OnCommandReceived(void *args);
	static Block* Init( volatile uint32_t* eventMask);
	static CommandType retrieveCommandFromString(void);
        static uint8_t messageBufIndex;
    static ErrorCode RegisterTask(Task *task);
	//static const uint8_t getMessageEndChar();
	inline static ErrorCode addMessagebyte(uint8_t byte) {
         if(messageBufIndex<MAX_CMD_STRING_LENTH)
          {
            	messageBuf[messageBufIndex++]=byte;
                return NO_ERR;
          }
             messageBufIndex=0;
             return FAIL;
	}
         inline static ErrorCode pullMessagebyte(void) {
         if(messageBufIndex>0)
          {
            	messageBufIndex--;
                return NO_ERR;
          }
           return FAIL;
	}
	~CommandHandler();
};

#endif /* COMMANDHANDLER_H_ */
